{% extends "smErp/base.html" %}

{% block css_style %}
    {% load staticfiles %}
    <link href="{% static 'smErp/css/register.css' %}" type="text/css" rel="stylesheet">

{% endblock %}



{% block content %}
    <!-- 二级导航 -->
    <div class="inner wrp">
        <div class="container_box cell_layout">
            <div class="col_side">
                <div class="menu_box">
                    <ul id="account_menu" class="menu">
                        <li class="menu_item selected">
                            <a href="javascript:;" data-page="base_info" class="menu_link jsUrlLink ">基本资料</a>
                        </li>
                        <li class="menu_item ">
                            <a href="javascript:;" data-page="change_password" class="menu_link jsUrlLink">修改密码</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="col_main" id="account_info_body" >
                <div class="main_hd">
                    <h2>邮箱信息</h2>
                </div>
                <div class="main_bd">
                    <div class="meta_content">
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">注册邮箱</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="email">{{ user_info.email }}</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="main_hd" style="padding-bottom: 5px">
                    <div style="float:right;">
                        <a id="js_btn_verify_qrcode" class="" href="{% url 'smErp:complete_company' %}" target="_self">修改</a>
                    </div>
                    <h2>企业信息</h2>
                </div>
                <div class="main_bd">
                    <div class="meta_content">
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">企业全称</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="full_name">{{ company_info.full_name }}</span>
                            </div>
                        </div>

                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">组织机构代码</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="organization_code">{{ company_info.organization_code }}</span>
                            </div>
                        </div>

                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">工商执照注册号</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="registration_no">{{ company_info.registration_no }}</span>
                            </div>
                        </div>

                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">法定代表人</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="representative">{{ company_info.representative }}</span>
                            </div>
                        </div>
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">一般经营范围</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="scope_normal">{{ company_info.scope_normal }}</span>
                            </div>
                        </div>
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">前置许可经营范围</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="representative">{{ company_info.scope_sepcial }}</span>
                            </div>
                        </div>
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">企业员工人数</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="staff_num">{{ company_info.staff_num }}</span>
                            </div>
                        </div>
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">管理员名称</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="manager">{{ company_info.manager }}</span>
                            </div>
                        </div>
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">管理员手机号码</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="manager_phone">{{ company_info.manager_phone }}</span>
                            </div>
                        </div>
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">管理员身份证号码</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="representative">{{ company_info.manager_id_card_no }}</span>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="col_main" id="change_password_body" style="display: none;">
                <div class="main_hd">
                    <h2>修改密码</h2>
                </div>
                <div class="main_bd">
                    <div class="meta_content">
                        <div class="frm_control_group show_value">
                            <label for="" class="frm_label">注册邮箱</label>
                            <div class="frm_controls frm_vm_pt">
                                <span class="frm_input_box" name="email">{{ user_info.email }}</span>
                            </div>
                        </div>
                    </div>
                    <form class="form" id="change_form" novalidate="novalidate">
                        {% csrf_token %}
                        <div class="frm_control_group" id="old_password_group">
                            <label for="" class="frm_label">原始密码</label>
                            <div class="frm_controls">
                            <span class="frm_input_box">
                                <input name="old_password" id="old_password" class="frm_input" type="password" value="{{ brand.name_zh }}">
                            </span>
                            </div>
                        </div>
                        <div class="frm_control_group" id="new_password_group">
                            <label for="" class="frm_label">新密码</label>
                            <div class="frm_controls">
                            <span class="frm_input_box">
                                <input name="new_password" id="new_password" class="frm_input" type="password" value="{{ brand.name_zh }}">
                            </span>
                            </div>
                        </div>
                        <div class="frm_control_group" id="confirm_password_group">
                            <label for="" class="frm_label">确认新密码</label>
                            <div class="frm_controls">
                            <span class="frm_input_box">
                                <input name="confirm_password" id="confirm_password" class="frm_input" type="password" value="{{ brand.name_zh }}">
                            </span>
                            </div>
                        </div>
                        <div class="tool_bar border with_form">
                            <a href="javascript:void(0);" class="btn btn_primary jsSendBt" id="changePwdBtn">提交</a>
                        </div>
                    </form>
                </div>

            <div>
        </div>
    </div>
{% endblock %}

{% block footscript %}
    <script>
        // 设置主菜单
        window.nav.selected("account");

        function show_nav_page(page){

            if(page == "base_info"){
                // 基本信息页
                $("#change_password_body").hide();
                $("#account_info_body").show();
            }else if(page == "change_password"){
                // 显示修改密码页
                $("#account_info_body").hide();
                $("#change_password_body").show();
            }else{
                return;
            }

        }

        var selected = $("#account_menu").children("li[class='menu_item selected']");
            $(".menu_link").on('click',function(){
            selected.removeClass("selected");
            $(this).parent().addClass("selected");
            selected = $(this).parent();
            show_nav_page($(this).data("page"));
        });


        $("#email").blur(function(){
{#           alert("hello world");#}
            var email = $("#email").val();
{#            alert(email);#}
            if(!email){
{#                alert("hellow");#}
                $("#email-msg").css("color","red");
                $("#email-msg").html("请输入邮箱地址");
                $("#email-msg").show();
            }
        });

        // 修改密码提交
        $("#changePwdBtn").on("click", function(){
            var old_password = $("#old_password").val();
            var new_password = $("#new_password").val();
            var confirm_password = $("#confirm_password").val();

            if(!old_password || !new_password || !confirm_password){
                if(!old_password){
                    layer.msg("请输入原始密码");
                }
                else if(!new_password){
                    layer.msg("请输入新密码");
                }
                else{
                    layer.msg("请再一次确认新密码");
                }
                return;
            }
            if(!check_password(new_password)){
                layer.msg("密码必须包含数字、字母，区分大小写，最短8位，区分大小写");
                return;
            }
            if(new_password != confirm_password){
                layer.msg("两次填写的新密码不一致");
                return;
            }
            var password_info = $("#change_form").serialize();
            $.post("{% url 'smErp:change_password' %}", password_info,
                    function(data, status, xhr){
                        if(status == "success") {
                            if(data.result == 0) {
                                // 密码修改成功，需重新登录
                                layer.msg("密码修改成功，请重新登录",{time:3000, end: function(){
                                    window.location.href = "{% url 'smErp:index' %}";
                                }});

                            }else{
                                layer.msg(data.reason);
                            }
                        }else{
                            layer.msg(status);
                        }

                },'json');
        });

    </script>
{% endblock %}




